# import time,os
# from selenium import webdriver
# from selenium.webdriver.common.by import By # todo:引入By方法，做selenium定位
# option = webdriver.ChromeOptions() # todo：chrome浏览器配置项
# option.add_experimental_option("detach", True)# todo：浏览器不会自动关闭
# bro = webdriver.Chrome(options=option) # todo：实例化driver
# # executable_path：指定driver的路径
# bro.get("https://www.baidu.com/") # todo：打开一个浏览器页面
# bro.maximize_window() # todo：浏览器放大
# #bro.minimize_window() # todo:浏览器缩小
# time.sleep(2) # todo：强制等待2s
# bro.find_element(By.ID, "kw").send_keys("selenium")
# time.sleep(3)
# bro.find_element(By.ID, "su").click()
# time.sleep(3)

import time
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.common.action_chains import ActionChains    #模拟鼠标的惭怍
from selenium.webdriver.support.wait import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC

driver = webdriver.Chrome()
driver.maximize_window()
wait = WebDriverWait(driver, 10,poll_frequency=0.5)
time.sleep(1)
driver.get("http://bilibili.com")
time.sleep(1)
driver.get("http://baidu.com")
time.sleep(2)
# driver.back()
# time.sleep(300)
# driver.forward()
# time.sleep(3)
# driver.close()
# print(driver.title)
# print(driver.current_url)
# print(driver.name)
# print(driver.page_source)


search_box = wait.until(EC.presence_of_element_located((By.ID, 'chat-textarea')))
search_box.send_keys("宇智波")
search_btn = wait.until(EC.presence_of_element_located((By.ID,'chat-submit-button')))
search_btn.click()
actions = ActionChains(driver)
setting = wait.until(EC.presence_of_element_located((By.CLASS_NAME, '_link_1iyz5_2')))
actions.move_to_element(setting).perform()
setting.click()
driver.switch_to.window(driver.window_handles[-1])
time.sleep(2)

driver.find_element(by=By.CLASS_NAME, value='searchInput').send_keys(Keys.CONTROL,'a')
driver.find_element(by=By.CLASS_NAME, value='searchInput').send_keys(Keys.CONTROL,'c')
driver.get("http://bilibili.com")
time.sleep(2)
driver.find_element(by=By.CLASS_NAME, value='nav-search-input').send_keys(Keys.CONTROL,'v',Keys.ENTER)
driver.switch_to.window(driver.window_handles[-1])
input("按回车关闭浏览器")
driver.close()















